/* DxfEntitySet.java
 *
 * Created on 6 de Dezembro de 2007, 9:21
 *
 * Modified 08/25/2011, 02:00 PM by Adriano
 * Included the attribute @Override to inherited methods
 */

package importadorDXF;

import java.util.Enumeration;
import java.util.Vector;

/**
 *
 * @author rafaelbuck
 * @author Adriano Ferreira 
 */
public class DxfEntitySet implements DxfConvertable, DxfEntityCollector
{
    @Override
    public void convert(DxfConverter converter, DxfFile dxf, Object collector)
    {
        converter.convert(this, dxf, collector);
    }

    @Override
    public boolean addEntity(DxfEntity entity)
    {
        if(entity instanceof DxfENDSEC)
        {
            return false;
        } else
        {
            entities.addElement(entity);
            counter.add(entity);
            return true;
        }
    }

    public DxfEntity getBlock(String name)
    {
        for(Enumeration e = entities.elements(); e.hasMoreElements();)
        {
            DxfEntity ent = (DxfEntity)e.nextElement();
            if(ent.isBlockNamed(name))
                return ent;
        }

        return null;
    }

    public final int getNrOfEntities()
    {
        return entities.size();
    }

    public Enumeration getEntities()
    {
        return entities.elements();
    }

    public Enumeration getCollectedEntityTypes()
    {
        return counter.getEntityNames();
    }

    public int getNumberOf(String entType)
    {
        return counter.getCount(entType);
    }

    public DxfEntity getEntity(int index)
    {
        return (DxfEntity)entities.elementAt(index);
    }

    /** Creates a new instance of DxfEntitySet */
    public DxfEntitySet()
    {
        entities = new Vector();
        counter = new DxfEntityCounter();
    }

    protected Vector entities;
    protected DxfEntityCounter counter;
}